﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using MVVMFramework.Core.Model;
using MVVMFramework.Core.ViewModel.Collections;
using Microsoft.Practices.ServiceLocation;

namespace MVVMFramework.Core.ViewModel
{
    public class ListVM<T> : ViewModelBase, IListVM<T>
    {
        private IDomainModel model;

        public ListVM() { }

        protected virtual IDomainModel CreateModel()
        {
            return ServiceLocator.Current.GetInstance<IDomainModel>();
        }

        public void Initialize(IListVMInitializeArgs args)
        {
            this.model = args.ExistingModel ?? this.CreateModel();
            var query = model.GetQuery<T>();
            this.Entities = new DomainCollectionView<T>(query, args.RequiresPaging);
            query.Load();
        }

        public IDomainCollectionView<T> Entities
        {
            get;
            private set;
        }
    }
}
